package com.zhuxulin.parsemid.event.track;

import java.io.IOException;
import java.io.InputStream;

import com.zhuxulin.parsemid.event.BaseMidiEvent;

public abstract class BaseTrackEvent extends BaseMidiEvent {
	/**
	 * Event type such as 0x80,0x90
	 */
	protected int type;
	/**
	 * Track channel from 0 to 15(0xF)
	 */
	protected int channel;
	/**
	 * Track event Parameter
	 */
	protected int V1;
	/**
	 * Track event Parameter
	 */
	protected int V2;

	public BaseTrackEvent(int tick, int delta, int type, int channel, int v1,
			int v2) {
		super(tick, delta);
		this.type = type;
		this.channel = channel;
		this.V1 = v1;
		this.V2 = v2;
	}

	public static BaseTrackEvent parseTrackEvent(long tick, long delta,
			int type, int channel, InputStream in) throws IOException {
		return null;
	}

	@Override
	public int compareTo(BaseMidiEvent o) {
		return 0;
	}

	@Override
	public byte[] getCmdBytes() {
		return (type == BaseTrackEvent.Type.PROGRAM_CHANGE || type == BaseTrackEvent.Type.CHANNEL_AFTER_TOUCH) ? new byte[] {
				(byte) ((type & channel) & 0xFF), (byte) (V1 & 0xFF) }
				: new byte[] { (byte) ((type & channel) & 0xFF),
						(byte) (V1 & 0xFF), (byte) (V2 & 0xFF) };
	}

	class Type {
		public static final int NOTE_OFF = 0x80;
		public static final int NOTE_ON = 0x90;
		public static final int NOTE_AFTER_TOUCH = 0xA0;
		public static final int CONTROLLER = 0xB0;
		public static final int PROGRAM_CHANGE = 0xC0;
		public static final int CHANNEL_AFTER_TOUCH = 0xD0;
		public static final int PITCH_BEND = 0xE0;
	}
}
